<extend name="Base:base" />
<block name="head">
    <style>
        a{color:#fff;}
        .checker{display: block !important;}
    </style>
</block>
<block name="content">
    <form action="{:U('Admin/Rbac/setAccess')}" method="post">
        <foreach name="nodes" item="app">
            <div class="span12">
                <div class="box paint color_2 app">
                    <div class="title">
                        <div class="row-fluid">
                            <h4>
                                 <label class="checkbox "><input type="checkbox" name="access[]" value="{$app.id}_1" level="1" <if condition='$app[access]'>checked='checked'</if> />{$app.title}</label>
                            </h4>
                        </div>
                    </div>
                    <!-- End .title -->
                    <div class="content">
                        <div class="tabbable tabs-left">
                            <ul id="tabExample2" class="nav nav-tabs">
                                <foreach name="app.child" item="action" key='actionKey'>
                                    <li <if condition="$actionKey eq 0">class="active"</if>>
                                    <a href="#action{$action.id}" data-toggle="tab">
                                        <label class="checkbox ">{$action.title}</label>
                                    </a>
                                    </li>
                                </foreach>
                            </ul>
                            <div class="tab-content">
                                <foreach name="app.child" item="action"  key='actionKey'>
                                    <div class="tab-pane fade <if condition='$actionKey eq 0'> in active</if>" id="action{$action.id}">
                                        <label class="checkbox "><input type="checkbox" name="access[]" value="{$action.id}_2" level="2" <if condition='$action[access]'>checked='checked'</if>/>选择控制器</label>
                                        <foreach name="action.child" item="method">
                                            <label class="checkbox "><input type="checkbox" name="access[]" value="{$method.id}_3" level="3" <if condition='$method[access]'>checked='checked'</if>/>{$method.title}</label>
                                        </foreach>
                                    </div>
                                </foreach>
                            </div>
                        </div>
                    </div>
                    <!-- End .content --> 
                    <input type="hidden" value="{$rid}" name="rid" />
                    <a href="{:U('Admin/Rbac/role')}" class="btn btn-primary">返回</a>     
                    <button type="submit" class='btn btn-default'> 保存</button>
                </div>
                <!-- End  .box --> 

            </div>
        </foreach>
    </form>
</block>
<block name="script">
    <script type="text/javascript">
        $(function () {
            $('input[level=1]').click(function () {
                var inputs = $(this).parents('.app').find('input');
                $(this).prop('checked') ? inputs.prop('checked', 'checked').parent('span').addClass('checked') : inputs.prop('checked', false).parent('span').removeClass('checked');
            });
            $('input[level=2]').click(function () {
                var inputs = $(this).parents('.tab-pane').find('input');
                $(this).prop('checked') ? inputs.prop('checked', 'checked').parent('span').addClass('checked') : inputs.prop('checked', false).parent('span').removeClass('checked');
            });

        });
    </script>
</block>

